package com.tarena.lbs.business.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.business.pojo.param.StoreParam;
import com.tarena.lbs.business.pojo.param.UserLocationParam;
import com.tarena.lbs.business.pojo.query.AreaStoreQuery;
import com.tarena.lbs.business.pojo.query.StoreQuery;
import com.tarena.lbs.business.pojo.vo.StoreVO;
import com.tarena.lbs.business.servcie.StoreService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "店铺相关功能接口")
@Slf4j
@RestController
public class StoreController {
	
	@Autowired
	private StoreService storeService;
	
	
	/**
	 * 新增店铺
	 *
	 * @param param 新增店铺参数
	 * @return 新增结果
	 * @throws BusinessException 业务异常
	 */
	@Operation(summary = "新增店铺")
	@PostMapping("/admin/basic/store/add")
	public Result<Void> save(@Validated @RequestBody StoreParam param) throws BusinessException {
		log.debug(">>>新增店铺-服务-入参：{}", param);
		storeService.save(param);
		return Result.success();
	}
	
	
	/**
	 * 分页查询店铺列表
	 *
	 * @param query 查询参数
	 * @return 店铺列表
	 * @throws BusinessException 业务异常
	 */
	@Operation(summary = "查询店铺列表")
	@PostMapping("/admin/basic/store/getAll")
	public Result<PageResult<StoreVO>> pageList(@RequestBody StoreQuery query) throws BusinessException {
		log.debug(">>>查询店铺列表-服务-入参：{}", query);
		PageResult<StoreVO> pageResult = storeService.getPageList(query);
		return new Result<>(pageResult);
	}
	
	
	/**
	 * 查询区域下店铺列表
	 *
	 * @param query 查询参数
	 * @return 店铺列表
	 * @throws BusinessException 业务异常
	 */
	@Operation(summary = "查询区域下的店铺列表")
	@PostMapping("/admin/basic/store/getStoreByCity")
	public Result<PageResult<StoreVO>> getStoreByCity(@RequestBody AreaStoreQuery query) throws BusinessException {
		log.debug(">>>查询区域下店铺列表-服务-入参：{}", query);
		PageResult<StoreVO> pageResult = storeService.getStoreByCity(query);
		return new Result<>(pageResult);
	}
	
	//手机小程序定位上报
	@Operation(summary = "手机小程序定位上报")
	@PostMapping("/basic/store/location")
	public Result<Void> location(@RequestBody UserLocationParam param)
			throws BusinessException {
		return Result.success();
	}
	
}
